package net.caixiaomi.info.shopkeeper.adapter;

import android.support.v4.content.ContextCompat;

import net.caixiaomi.info.R;
import net.caixiaomi.info.app.CommonApp;
import net.caixiaomi.info.base.quickadapter.BaseMultiItemQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.shopkeeper.entity.ShopOrderEntity;
import net.caixiaomi.info.util.Constants;

import java.util.List;

/**
 * Created by mac on 2018/11/16.
 */

public class ShopOrderAdapter extends BaseMultiItemQuickAdapter<ShopOrderEntity, BaseViewHolder> {

    private int mType=0;
    public void setType(int type){
        mType=type;
    }

    public ShopOrderAdapter(List<ShopOrderEntity> data) {
        super(data);
        addItemType(Constants.ITEM_VIEW_EMPTY, R.layout.shop_order_item_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, ShopOrderEntity item) {
        try {
            switch (item.getItemType()) {
                case Constants.ITEM_VIEW_EMPTY:
                    bindData(helper, item);
                    break;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void bindData(BaseViewHolder helper, ShopOrderEntity item){
        helper.setText(R.id.shop_order_sn_tv,"订单编号:"+item.getOrderSn());
        String status=mType==0?item.getStatus():item.getOptType();
            switch (status) {
                case "0":   //未操作
                    helper.setTextColor(R.id.shop_order_sn_tv, ContextCompat.getColor(CommonApp.getInstance(), net.caixiaomi.info.R.color.primary_text));
                    break;
                case "1":   //成功
                    helper.setTextColor(R.id.shop_order_sn_tv, ContextCompat.getColor(CommonApp.getInstance(), R.color.green));
                    break;
                case "2":   //失败
                    helper.setTextColor(R.id.shop_order_sn_tv, ContextCompat.getColor(CommonApp.getInstance(), R.color.orange_primary));
                    break;
            }
    }

}
